from lxml import etree
import requests

root = etree.Element('html')
body = etree.Element('body')

root.append(body)

ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 ' \
     'Safari/537.36 '
urls = ['https://movie.douban.com']
session = requests.Session()
with session:
    for url in urls:
        response = session.get(url, headers={
            'User-agent': ua
        })
        content = response.text
        html = etree.HTML(content)
        titles = html.xpath("//div[@class='billboard-bd']//tr//text()")
        for t in titles:
            ## strip 去空格
            if (len(t.strip()) > 0):
                print(t)
